package Controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Model.Bean.*;
import Model.Dao.*;



/**
 * Servlet implementation class setTaskServlet
 */
public class setTaskServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * Default constructor.
	 */
	public setTaskServlet() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String button = request.getParameter("submit");
		System.out.println(button);
		System.out.println(button);
		if (button.equals("submit")) {
			String title = request.getParameter("title");
			String content = request.getParameter("content");
			String startDate = request.getParameter("startDate");
			String endDate = request.getParameter("endDate");
			float reward = Float.parseFloat(request.getParameter("reward"));
			float cpp = Float.parseFloat(request.getParameter("cpp"));
			float Java = Float.parseFloat(request.getParameter("Java"));
			float csharp = Float.parseFloat(request.getParameter("csharp"));
			float oracle = Float.parseFloat(request.getParameter("oracle"));
			float python = Float.parseFloat(request.getParameter("python"));
			float php = Float.parseFloat(request.getParameter("php"));
			int commentnum = Integer.parseInt(request
					.getParameter("commentnum"));
			float averagemark = Float.parseFloat(request
					.getParameter("averagemark"));
			SetTaskDao sb = new SetTaskDao();
			TaskBean td = new TaskBean();
			td = sb.SetTask(content, title, startDate, endDate, reward, cpp,
					Java, csharp, oracle, python, php, commentnum, averagemark);
			sb.insertodatabase(td);
		} else {
			System.out.println("get in");
			SearchTaskDao st=new SearchTaskDao();
			ArrayList<TaskBean> al=new ArrayList<TaskBean>();
			al=st.getList();
			if(al.size()>0){
			
			for(int i=0;i<al.size();i++){
				System.out.println(al.get(i).getContent());
			}
			System.out.println(al.get(1).getAveragemark());
			}
			else{
				System.out.println("No such data");
			}
//			SearchTaskBean st=new SearchTaskBean();
//			ArrayList<TaskDao> al=st.getList();
			request.setAttribute("task", al);
			request.getRequestDispatcher("list.jsp").forward(
					request, response);
		}

		// TODO Auto-generated method stub
	}
}
